#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
int t,n,a[N],f[N],s[N],c[N];
map<int,int> h;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        int cnt=0;
        h.clear();
        for(int i=1;i<=n;i++){
            cin>>a[i];
            s[i]=s[i-1]+((a[i]==a[i-1])?a[i]:0);
            if(!h[a[i]]){
                h[a[i]]=++cnt;
                c[cnt]=-0x3f3f3f3f;
            }
        }
        int mx=0;
        for(int i=1;i<=n;i++){
            int u=h[a[i+1]],w=h[a[i]];
            f[i]=max(mx,c[u])+s[i];
            mx=max(mx,f[i]-s[i+1]);
            c[w]=max(c[w],f[i]-s[i+1]+a[i]);
        }
        cout<<f[n]<<'\n';
    }
    return 0;
}
